//
//  JpToolbar.m
//  XPComDemo
//
//  Created by Junjie Gong on 12-5-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "JpToolbar.h"
#import "MyWindowController.h"

@interface JpToolbar()

- (void)messageHandler:(id)object;

@end

@implementation JpToolbar


- (id)init{
    if (!(self=[super init])) {
        return nil;
    }
    
    NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self
           selector:@selector(toolbarButtonMessageHandler:) 
               name:@"toolbar_message_handler" 
             object:nil];
    
    
    return self;
}
     
- (void)toolbarButtonMessageHandler:(NSNotification *)notification{
    NSLog(@"start message handle");
    
//    notification.userInfo
    
//    MyWindowController *c = [[MyWindowController alloc] init];
//    [NSApp runModalForWindow:c.window];
//    [c release];
}


- (void)messageHandler:(id)object{
    NSLog(@"messageHandler");
    MyWindowController *c = [[MyWindowController alloc] init];
    [NSApp runModalForWindow:c.window];
    [c release];
}

- (void)sendMessageWithObject:(id)object{
    NSLog(@"sendMessageWithObject");
    [self performSelector:@selector(messageHandler:) withObject:object];
}

- (void)postMessageWithObject:(id)object{
    NSLog(@"postMessageWithObject");
    [self performSelectorOnMainThread:@selector(messageHandler:) withObject:object waitUntilDone:NO];
}

@end
